﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Alex.Library.Net.Web
{
    /// <summary>
    /// 获取Http响应流的事件委托
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public delegate void ResponseEventHandler(object sender, ResponseEventArgs e);
    
    /// <summary>
    /// 获取Http响应流的事件参数
    /// </summary>
    public class ResponseEventArgs : EventArgs
    {
        /// <summary>
        /// 默认构造函数
        /// </summary>
        public ResponseEventArgs()
        {
            this.State = ResponseState.BeforeResponse;
            this.ReceiveBytes = 0;
            this.TotalBytes = 0;
            this.Duration = TimeSpan.Zero;            
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="state">当前状态</param>
        /// <param name="receiveBytes">当前接收的字节数</param>
        /// <param name="totalBytes">响应流总的字节数</param>
        /// <param name="duration">持续的时长</param>
        /// <param name="exception">当State=Error时的异常信息对象</param>
        public ResponseEventArgs(ResponseState state, long receiveBytes, 
            long totalBytes, TimeSpan duration)
        {
            this.State = state;
            this.ReceiveBytes = receiveBytes;
            this.TotalBytes = totalBytes;
            this.Duration = duration;            
        }

        /// <summary>
        /// 当前状态
        /// </summary>
        public ResponseState State { get; private set; }

        /// <summary>
        /// 当前接收的字节数
        /// </summary>
        public long ReceiveBytes { get; private set; }

        /// <summary>
        /// 本次请求的响应流总字节数
        /// </summary>
        public long TotalBytes { get; private set; }

        /// <summary>
        /// 持续的时长
        /// </summary>
        public TimeSpan Duration { get; private set; }
    }    
}
